<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax gat请求，显示响应体</title>
    <style>
        #result{
            width: 200px;
            height: 200px;
            border: 1px solid #ccc;
        }
    </style>
</head>
<body>
    <button>点击发送请求</button>
    <div id="result"></div>
<script>
    var button=document.querySelector('button');
    var div=document.querySelector('#result');
    button.addEventListener('click',function(){
        const xhr=new XMLHttpRequest();
        xhr.open('GET','http://127.0.0.1:5050/server');
        xhr.send();
        xhr.addEventListener('readystatechange',function (){
            //返回了全部
            if(xhr.readyState===4){
                //状态码显示为成功
                if(xhr.status>=200&&xhr.status<300){
                    div.innerHTML=xhr.response;
                }
            }
        })
    })
</script>
</body>
</html>